import wx
import wx.adv
from src.pc_info import pc_info
from src.frame import task_aui_frame
from src.AI_chat import AiChatWindow

TRAY_ICON = '../resources/computer.png'
TRAY_TOOLTIP = '示例'


class Task(wx.adv.TaskBarIcon):
    def __init__(self):
        super().__init__()

        icon = wx.Icon(TRAY_ICON)
        self.SetIcon(icon, TRAY_TOOLTIP)
        self.ai_chat_frame = None
        self.task_frame = None
        self.pc_info_frame = None
        self.Bind(wx.adv.EVT_TASKBAR_RIGHT_DOWN, self.OnRightClick)

    def creat_menu_item(self, menu, label, func):
        item = wx.MenuItem(menu, -1, label)
        menu.Bind(wx.EVT_MENU, func, id=item.GetId())
        menu.Append(item)
        return item

    def OnRightClick(self, event):
        menu = wx.Menu()
        self.creat_menu_item(menu, "pc_info", self.OnPcInfo)
        self.creat_menu_item(menu, "frame", self.OnFrame)
        self.creat_menu_item(menu, "ai_chat", self.OnAiChat)
        menu.AppendSeparator()

        menu.Append(wx.ID_EXIT, "E&xit")
        self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)

        self.PopupMenu(menu)
        menu.Destroy()

    def on_task(self, event):
        self.task_frame = task_aui_frame(None, "任务管理")
        self.task_frame.Show(True)

    def OnAiChat(self, event):
        if self.ai_chat_frame is None:
            self.ai_chat_frame = AiChatWindow(None)
        self.ai_chat_frame.Show(True)

    def OnPcInfo(self, event):
        if self.pc_info_frame is None:
            self.pc_info_frame = pc_info(None)
        self.pc_info_frame.Show(True)

    def OnFrame(self, event):
        frame = task_aui_frame(None, "wx.aui.AuiNotebook Example")
        frame.Show(True)
        return True

    def OnExit(self, event):
        wx.GetApp().ExitMainLoop()


class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, wx.ID_ANY, "example")
        self.SetTopWindow(frame)
        Task()
        return True


if __name__ == "__main__":
    app = MyApp()
    app.MainLoop()
